define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'kechengbiao/index' + location.search,
                    add_url: 'kechengbiao/add',
                    edit_url: 'kechengbiao/edit',
                    del_url: 'kechengbiao/del',
                    multi_url: 'kechengbiao/multi',
                    table: 'school_class_subject_schedule',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'date',
                sortOrder: 'asc',
                search: false,
                commonSearch: false,
                showToggle: false,
                showColumns: false,
                showExport: false,
                columns: [
                    [
                        {field: 'id', title: '编号'},
                        {field: 'date', title: __('Date'), operate: 'RANGE', addclass: 'datetimerange'},
                        {field: 'time_slot', title: __('Time_slot')},
                        {
                            field: 'status',
                            title: __('Status'),
                            searchList: {"0": __('Status 0'), "1": __('Status 1'), "2": __('Status 2')},
                            formatter: Table.api.formatter.status
                        },

                        //{field: 'user_status', title: __('User_status')},
                        {
                            field: 'createtime',
                            title: __('Createtime'),
                            operate: 'RANGE',
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime
                        },
                        //{field: 'is_notice', title: __('Is_notice')},
                        {field: 'admin.nickname', title: '授课老师', operate: false},
                        {field: 'schoolclass.class_name', title: __('Schoolclass.class_name')},
                        {field: 'transfer_id', title: '调课编号'},
                        {field: 'transfer_remarks', title: __('Transfer_remarks'), operate: false},
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
            Controller.api.bindevent();
            $("#c-class_id").on("keyup drop blur", function () {
                console.log($('#c-class_id').val());
                table.bootstrapTable('refresh', {
                    url: 'kechengbiao/index/xiaobao/' + $('#c-class_id').val() + location.search,
                });
            });
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});